package com.Pure;

import com.e3roid.E3Activity;
import com.e3roid.drawable.Sprite;
import com.e3roid.drawable.texture.AssetTexture;
import com.e3roid.drawable.texture.Texture;
import android.graphics.Point;
public class PureGameFactory {
	 
	private Texture texRay;
	private Texture texMirror;
	private Texture texGrid;
	private Texture texVempire;
	private Texture texBlock;
	private E3Activity main;
	 
	//private Texture texBlackbar;
	
	public PureGameFactory(E3Activity main)
	{
		this.main = main;
	}
	public void loadResource()
	{
		texRay = new AssetTexture("lightRay.png",main);
		texMirror = new AssetTexture("mirror.png",main);
		texGrid = new AssetTexture("grid.png",main);
		texVempire = new AssetTexture("vempire.png",main);
		texBlock = new AssetTexture("block.png",main);
		
		//texBlackbar = new AssetTexture("BlackBar.png",main);
		
		texRay.setReusable(true);
		texMirror.setReusable(true);
		texGrid.setReusable(true);
		texVempire.setReusable(true);
		texBlock.setReusable(true);
		
		//texBlackbar.setReusable(true);
	}
	public PureLightSource createLightSource(int girdX,int gridY,PureLightDirection d)
	{
		//texRay = new AssetTexture("lightRay.png",main);
		Sprite sourceSprite = new Sprite(texRay,0,0);
		
		sourceSprite.setRotationAndScaleCenter(sourceSprite.getWidth() / 2, sourceSprite.getHeight() / 2);
		
		PureLightSource source = new PureLightSource(sourceSprite,girdX,gridY,d);
		return source;
	}
	public PureLightRay createLightRay(Point start,int gridDistance,PureLightDirection d,float width)
	{
		//texRay = new AssetTexture("lightRay.png",main);
		Sprite lightRaySprute = new Sprite(texRay,0,0);
		lightRaySprute.setRotationAndScaleCenter(0, PureGrid.getGridSize() / 2);
		
		
		int length = gridDistance;
		
		lightRaySprute.scale(1.0f / 32.0f * length * (float)PureGrid.getGridSize(),1.0f / 32.0f * width);
		
		PureLightRay ray = new PureLightRay(lightRaySprute,start,gridDistance,d);
		return ray;
	}
	public PureLightRay createLightRay(int x,int y,float length,float width)
	{
		//texRay = new AssetTexture("lightRay.png",main);
		Sprite lightRaySprute = new Sprite(texRay,x,y);
		lightRaySprute.setRotationAndScaleCenter(0, PureGrid.getGridSize() / 2);
		
		lightRaySprute.scale(1.0f / 16.0f * length,1.0f / 16.0f * width);
		
		PureLightRay ray = new PureLightRay(lightRaySprute);
		return ray;
	}
	public PureMirror createMirror(int x,int y,float rotation)
	{
		//texMirror = new AssetTexture("mirror.png",main);
		Sprite mirrorSprite = new Sprite(texMirror,x,y);
		mirrorSprite.rotate(rotation);
		mirrorSprite.setRotationAndScaleCenter(mirrorSprite.getWidth()/2, mirrorSprite.getHeight()/2);
		
		PureMirror mirror = new PureMirror(mirrorSprite);
		((PureMain)main).level.addEventListener(mirror.getSprite());
		
		return mirror;
	}
	public PureVempire createVempire(int x,int y)
	{
		//texVempire = new AssetTexture("vempire.png",main);
		Sprite vempireSprite = new Sprite(texVempire,x,y);
		
		vempireSprite.setRotationAndScaleCenter(vempireSprite.getWidth()/2, vempireSprite.getHeight()/2);
		
		PureVempire vempire = new PureVempire(vempireSprite);
		return vempire;
	}
	public PureBlock createBlock(int x,int y)
	{
		//texBlock = new AssetTexture("block.png",main);
		Sprite blockSprite = new Sprite(texBlock,x,y);
		
		blockSprite.setRotationAndScaleCenter(blockSprite.getWidth()/2, blockSprite.getHeight()/2);
		
		PureBlock block = new PureBlock(blockSprite);
		return block;
	}
	public PureGrid createGrid()
	{
		
		PureGrid grid = new PureGrid(new Sprite(texGrid,0,64),32);
		return grid;
	}
	/*
	public Sprite createBar()
	{
		Sprite blackbarSprite = new Sprite(texBlackbar,0,0);
		return blackbarSprite;
	}
	*/
}
